/**
 * Copyright (c) 2010-2011 julewa.com.  
 * All rights reserved. 
 * 
 * @author Huang Benhua
 * @date 2011-7-2
 * 
**/
package com.julewa.db.ibatis;

import java.util.HashSet;
import java.util.Set;

import com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactory;
import com.julewa.loading.SpringLoader;

public class IbatisResultObjectFactory implements ResultObjectFactory{
	
	//to create any one...
	private Set<Class<?>> autowires = new HashSet<Class<?>>();

	@Override
	public void setProperty(String key, String value) {
		try {
			autowires.add(Class.forName(value));
		} catch (ClassNotFoundException e) {}
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public Object createInstance(String arg0, Class clazz)
			throws InstantiationException, IllegalAccessException {
		if(autowires.contains(clazz)){
			return SpringLoader.getInstance(clazz);
		}
		return null;
	}

}
